#!/bin/bash
#
# 29/09/2006 - Vincenzo Tozzi - vincenzo.tozzi@planalto.gov.br - ramal 3334
#
# Pode ser esecutado automaticamente fazendo 'crontab -e' e colocando (para rodar todos os dias as 3.30 da manha):
# SHELL=/bin/bash
# # Backup Data.fs do Zope
# 30 3 * * * /home/zope/bin/backup
#

export http_proxy=http://10.1.101.101:8080
export PYTHONPATH=/home/zope/zope2.9/lib/python

PYTHON=/home/zope/python2.4/bin/python
ZOPEUTIL=/home/zope/zope2.9/bin
BCK_DIR=/home/zope/backups
ZEO_DIR=/home/zope/instancias/zeo

echo ":: Relatorio de backup do Data.fs (iaco) ::" > message.txt

date >> message.txt

mv $BCK_DIR/*.dat $BCK_DIR/antigo/
mv $BCK_DIR/*.fs $BCK_DIR/antigo/

echo "Fazendo o pack do ZEO ..." >> message.txt
$PYTHON $ZOPEUTIL/zeopack.py -p 8100 -d 7 2> tempfile
cat tempfile >> message.txt

echo "Fazendo backup incremental do Data.fs ..." >> message.txt
$PYTHON $ZOPEUTIL/repozo.py -B -v -r $BCK_DIR -f $ZEO_DIR/var/Data.fs 2> tempfile

cat tempfile >> message.txt

# Copia em outro servidor
echo "Copiando o backup no servidor (grande 10.1.2.150)..." >> message.txt
scp -rv $BCK_DIR/*.fs iaco@10.1.2.150:backup/ 2> tempfile
scp -rv $BCK_DIR/*.dat iaco@10.1.2.150:backup/ 2> tempfile
cat tempfile >> message.txt

date >> message.txt

cat message.txt | mailx -s 'Cron Job: backup zope' zope

rm message.txt tempfile
